package com.github.thinwonton.springboot.showcase.jta.mybatisplus.account.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.github.thinwonton.springboot.showcase.jta.mybatisplus.account.dao.AccountMapper;
import com.github.thinwonton.springboot.showcase.jta.mybatisplus.account.domain.Account;
import com.github.thinwonton.springboot.showcase.jta.mybatisplus.account.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;

@Service
public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> implements AccountService {

    @Autowired
    private AccountMapper accountMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void createAccount() {
        Account account = new Account();
        account.setAccountId(String.valueOf(System.currentTimeMillis()));
        account.setMoney(new BigDecimal(30.9));
        accountMapper.insert(account);
    }

    @Override
    public int deleteAll() {
        return accountMapper.deleteAll();
    }

    @Override
    public Page<Account> selectAccountPage(Page<Account> page) {
        return page.setRecords(accountMapper.selectAccountList(page));
    }
}
